﻿/*
 * Created by SharpDevelop.
 * User: Home
 * Date: 15/11/2008
 * Time: 16:00
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace csharp.rad.finan.entries
{
	/// <summary>
	/// Description of frmRegisterGroup.
	/// </summary>
	public partial class frmRegisterGroup : csharp.common.RegisterTemplate
	{
		private Group group;
		private Groups list;
		
		public frmRegisterGroup()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			group = new Group();
			list  = new Groups();
		}
		
		protected override void newEvent()
		{
			group.clear();
		}
		
		/// <summary>
		/// Set data from edits to class
		/// </summary>
		protected override void setClass()
		{
			group.code= txtCode.Text;
			group.name= txtGroup.Text;
			group.active= cbxActive.Checked;
		}
		
		/// <summary>
		/// Set data from class to edits
		/// </summary>
		protected override void setEdits()
		{
			group.id= dgvMain.CurrentRow.Cells["id"].Value.ToString();
			
			if (group.get())
			{
				txtCode.Text= group.code;
				txtGroup.Text= group.name;
				cbxActive.Checked= group.active;
			}
		}
		
		/// <summary>
		/// Fill the DataGridView
		/// </summary>
		protected override void fillDataGridView()
		{
			int tam;
			
			list.fillList();
			dgvMain.Rows.Clear();
			tam= list.count();
			for (int i=0; i < tam; i++)
			{
				String []row= {list.get(i).id, list.get(i).code, list.get(i).name};
				dgvMain.Rows.Add(row);
			}
		}
		
		/// <summary>
		/// Find the object of search
		/// </summary>
		protected override void find()
		{
			common.Util.searchInGrid(dgvMain, "name", txtSearch.Text);
		}		
		
	   /// <summary>
	   /// Save the register in the database.
	   /// </summary>
	   /// <returns>bool - true if the register was saved sucessful, false case not.</returns>	
	   protected override bool save()
	   {
	   	return group.save();
	   }
	   
	   /// <summary>
	   /// Update the register in the database
	   /// </summary>
	   /// <returns>bool - true if the register was updated sucessful, false case not.</returns>
	   protected override bool update()
	   {   
	   	return group.update();
	   }
	   
	   /// <summary>
	   /// Delete the register in the database.
	   /// </summary>
	   /// <returns>bool - true if the register was deleted sucessful, false case not.</returns>
	   protected override bool delete()
	   {
	   	group.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();
	   	return group.delete();
	   }
	   
	   /// <summary>
	   /// Method call in initialization
	   /// </summary>
	   protected override void init()
	   {
	   	KryptonDataGridViewTextBoxColumn id   = new KryptonDataGridViewTextBoxColumn();
	   	KryptonDataGridViewTextBoxColumn code = new KryptonDataGridViewTextBoxColumn();
	   	KryptonDataGridViewTextBoxColumn name = new KryptonDataGridViewTextBoxColumn();
	   	
	   	dgvMain.Columns.AddRange(new DataGridViewColumn[] {id,code,name});
	   	
	   	id.Name= "id";
	   	id.Visible= false;
	   	
	   	code.Name = "code";
	   	code.HeaderText= "Código";
	   	
	   	name.Name= "name";
	   	name.Width= 200;
	   	name.HeaderText = "Nome";
	   }		
		
		private void TabPrincipalEnter(object sender, EventArgs e)
		{
			txtCode.Focus();
		}
	}
}
